//
//  UIWindow+extence.m
//  彩票
//
//  Created by mac on 15-3-29.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "UIWindow+extence.h"
#import "YXTabBarController.h"
#import "YXViewController.h"

@implementation UIWindow (extence)

- (void)chooseRootViewController
{
   
    // 4.加载新特性
    // 4.1获取当前版本号并对比之前保存版本号
    NSString *currentNum = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    // NSLog(@"currentNum==%@",currentNum);
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *previousNum = [defaults valueForKey:@"sandboxVersion"];
    if ([currentNum compare:previousNum] == NSOrderedDescending/*currentNum > previousNum */ ) {
        // 显示新特性并保存版本号
        YXViewController *newFeature = [[YXViewController alloc] init];
        self.rootViewController = newFeature;
        [defaults setValue:currentNum forKey:@"sandboxVersion"];
        // 注册监听
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(chooseTabbarVc) name:@"chooseRootController" object:nil];
        
    }else{
        
        YXTabBarController *vc = [[YXTabBarController alloc] init];
        // 5.设置WINDOW的根控制器
        self.rootViewController = vc;
    }

}

- (void)chooseTabbarVc
{
    YXTabBarController *vc = [[YXTabBarController alloc] init];
    self.rootViewController = vc;
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
